package com.handpay.zztong.hp.main.model;

import android.content.Context;

import com.handpay.framework.KxbActivity;
import com.handpay.zztong.hp.accountcenter.activity.BankCardManagerActivity;
import com.handpay.zztong.hp.accountcenter.activity.BaseInfoActivity;
import com.handpay.zztong.hp.db.ormlite.DataBaseComponentModel;
import com.handpay.zztong.hp.log.HPLog;
import com.handpay.zztong.hp.main.model.component.ComponentItemBean;
import com.handpay.zztong.hp.onlineshop.activity.JieAnHtmlActivity;
import com.handpay.zztong.hp.onlineshop.activity.ShowLoanHtmlActivity;
import com.handpay.zztong.hp.swiper.activity.ConnectSwiperActivity;
import com.handpay.zztong.hp.qualification.activity.IDCardateActivity;
import com.handpay.zztong.hp.main.activity.AllFunctionActivity;
import com.handpay.zztong.hp.main.activity.MainActivity;
import com.handpay.zztong.hp.notification.activity.NoticeActivity;
import com.handpay.zztong.hp.accountcenter.activity.QualificationInfoActivity;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.other.activity.ShowHtmlActivity;
import com.handpay.zztong.hp.onlineshop.activity.ShowMarketHtmlActivity;
import com.handpay.zztong.hp.trans.activity.SuperTransferAccountsActivity;
import com.handpay.zztong.hp.qualification.activity.T0QualificationActivity;
import com.handpay.zztong.hp.accountcenter.activity.TransferCashLimitManagementActivity;
import com.handpay.zztong.hp.webpay.activity.ScannerCodePayActivity;
import com.handpay.zztong.hp.withdraw.activity.WithdrawActivity;
import com.handpay.zztong.hp.paymentbill.activity.QueryBillsActivity;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 主界面显示的组建
 *
 * @author dlfeng
 *         2015/5/14
 */
public class FunctionInfo {


    public static final String COLLECT_MONEY_ICON_CODE = "collect_money";
    public static final String SCAN_PAYMENT_ICON_CODE = "scan_payment";
    public static final String MONG_HOO_ICON_CODE = "mong_hoo";
    public static final String HONG_SHOP_ICON_CODE = "hong_shop";
    public static final String LOAN_PACKAGE_ICON_CODE = "loan_package";
    public static final String STOCK_FUND_ICON_CODE = "stock_fund";
    public static final String QQ_IM_ICON_CODE = "qq_im";
    public static final String GATHER_APP_ICON_CODE = "gather_app";
    public static final String JIEAN_ICON_CODE = "jiean_dai";
    public static final String MOBILE_RECHARGE_ICON_CODE = "mobile_recharge";
    public static final String LOAN_ICON_CODE = "loan_dai";
    public static final String FAST_TRANSFER_ICON_CODE = "fast_transfer";
    public static final String CREDIT_CARD_ICON_CODE = "credit_card";
    public static final String NO_CARD_PAYMENT_ICON_CODE = "nocard_payment";
    public static final String QR_CODE_ICON_CODE = "qrcode_payment";


//    public static final String MY_BASIC_INFO_ICON_CODE = "basicinfo";
//    public static final String MY_QUALIFICATION_INFO_ICON_CODE = "qualificationinfo";
//    public static final String MY_COLLECT_CARD_MANAGEMENT_ICON_CODE = "collectcardmanagement";
//    public static final String MY_COLLECT_LIMIT_ICON_CODE = "collectlimit";
//    public static final String MY_COLLECT_FLOW_ICON_CODE = "collectflow";


    public static final String COLLECT_MONEY_CODE = "collectMoney";                         //收款
    public static final String SCAN_PAYMENT_CODE = "scanPayment";                           //扫码支付
    public static final String MONG_HOO_CODE = "mongHoo";                                   //代还信用卡
    public static final String HONG_SHOP_CODE = "onlineMarket";                             //在线商城
    public static final String LOAN_PACKAGE_CODE = "loanPackage";                           //贷款目录
    public static final String STOCK_FUND_CODE = "stockFund";                               //证券开户
    public static final String QQ_IM_CODE = "qqIm";                                         //在线咨询
    public static final String GATHER_APP_CODE = "gatherApp";                               //全部应用
    public static final String JIEAN_CODE = "jieAn";                                        //捷安借贷
    public static final String MOBILE_RECHARGE_CODE = "mobileRecharge";                     //话费充值
    public static final String LOAN_CODE = "loan";                                          //贷款
    public static final String FAST_TRANSFER_CODE = "fastTransfer";                         //快速转账
    public static final String CREDIT_CARD_CODE = "creditCard";                             //信用卡还款
    public static final String NO_CARD_PAYMENT_CODE = "noCardPayment";                      //无卡支付
    public static final String QR_CODE_CODE = "qrcodePayment";                              //码上付
    public static final String MY_BASIC_INFO_CODE = "basicinfo";                            //基本信息
    public static final String MY_QUALIFICATION_INFO_CODE = "qualificationinfo";            //资质信息
    public static final String MY_COLLECT_CARD_MANAGEMENT_CODE = "collectcardmanagement";   //收款卡管理
    public static final String MY_COLLECT_LIMIT_CODE = "collectlimit";                      //收款限额
    public static final String MY_COLLECT_FLOW_CODE = "collectflow";                        //收款流水
    public static final String MY_SWIPE_SELECT_CODE = "swipeselect";                        //刷卡器连接
    public static final String MY_USER_NOTICE_CODE = "usernotice";                          //用户通知
    public static final String MY_T0_QUALIFICATION_CODE = "T0Qualification";                //TO资质提现
    public static final String MY_ID_Cardate_CODE = "IDCardate";                            //证件补传
    public static final String MY_COLLECT_WITHDRAW_CODE = "collectwithdraw";                //收款提现


    public String itemId;
    public String title;
    public int[] iconResId;
    public String iconUrl;
    public Class<?> cls;
    //    public boolean isCheckSwiper = false;
//    public boolean isStartActivity = true;
//    public int iconIndex = 0;
    public int index;
    public int showModule;
    public String type;

    public FunctionInfo(String itemId, String title, int[] iconResId, Class<?> cls) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.cls = cls;
        this.type = "1";
    }

    public FunctionInfo(String itemId, String title, int[] iconResId, Class<?> cls, String type) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.cls = cls;
        this.type = type;
    }

    public FunctionInfo(String itemId, String title, int[] iconResId, Class<?> cls, boolean isCheckSwiper, boolean isStartActivity) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.cls = cls;
//        this.isCheckSwiper = isCheckSwiper;
//        this.isStartActivity = isStartActivity;
    }

    public static int getDrawableResIdByItemCode(String itemCode) {
        if (itemCode.equals(COLLECT_MONEY_CODE)) {
            return R.drawable.home_icon_receivables;
        } else if (itemCode.equals(SCAN_PAYMENT_CODE)) {
            return R.drawable.home_icon_scanner_code_pay;
        } else if (itemCode.equals(MONG_HOO_CODE)) {
            return R.drawable.home_icon_loan_credit;
        } else if (itemCode.equals(HONG_SHOP_CODE)) {
            return R.drawable.home_icon_market;
        } else if (itemCode.equals(LOAN_PACKAGE_CODE)) {
            return R.drawable.home_icon_loan_package;
        } else if (itemCode.equals(STOCK_FUND_CODE)) {
            return R.drawable.home_open_account_aop;
        } else if (itemCode.equals(QQ_IM_CODE)) {
            return R.drawable.home_icon_qq_consultation;
        } else if (itemCode.equals(GATHER_APP_CODE)) {
            return R.drawable.home_icon_all_funciton;
        } else if (itemCode.equals(JIEAN_CODE)) {
            return R.drawable.home_icon_jiean;
        } else if (itemCode.equals(MOBILE_RECHARGE_CODE)) {
            return R.drawable.home_icon_phone_chongzhi;
        } else if (itemCode.equals(LOAN_ICON_CODE)) {
            return R.drawable.home_icon_loan;
        } else if (itemCode.equals(FAST_TRANSFER_CODE)) {
            return R.drawable.home_icon_fast_transfer;
        } else if (itemCode.equals(CREDIT_CARD_CODE)) {
            return R.drawable.home_icon_credit_card;
        } else if (itemCode.equals(NO_CARD_PAYMENT_CODE)) {
            return R.drawable.home_icon_no_card_payment;
        } else if (itemCode.equals(QR_CODE_CODE)) {
            return R.drawable.home_icon_qr_code;
        } else {
            return R.drawable.home_icon_receivables;
        }
    }

    public static int getDrawableResIdByFunctionIconName(String iconName, String itemCode) {
        HPLog.i(HPLog.YL_TAG, "iconName：" + iconName + " itemCode：" + itemCode);
        if (iconName.equals(COLLECT_MONEY_ICON_CODE)) {
            return R.drawable.home_icon_receivables;
        } else if (iconName.equals(SCAN_PAYMENT_ICON_CODE)) {
            return R.drawable.home_icon_scanner_code_pay;
        } else if (iconName.equals(MONG_HOO_ICON_CODE)) {
            return R.drawable.home_icon_loan_credit;
        } else if (iconName.equals(HONG_SHOP_ICON_CODE)) {
            return R.drawable.home_icon_market;
        } else if (iconName.equals(LOAN_PACKAGE_ICON_CODE)) {
            return R.drawable.home_icon_loan_package;
        } else if (iconName.equals(STOCK_FUND_ICON_CODE)) {
            return R.drawable.home_open_account_aop;
        } else if (iconName.equals(QQ_IM_ICON_CODE)) {
            return R.drawable.home_icon_qq_consultation;
        } else if (iconName.equals(GATHER_APP_ICON_CODE)) {
            return R.drawable.home_icon_all_funciton;
        } else if (iconName.equals(JIEAN_ICON_CODE)) {
            return R.drawable.home_icon_jiean;
        } else if (iconName.equals(MOBILE_RECHARGE_ICON_CODE)) {
            return R.drawable.home_icon_phone_chongzhi;
        } else if (iconName.equals(LOAN_ICON_CODE)) {
            return R.drawable.home_icon_loan;
        } else if (iconName.equals(FAST_TRANSFER_ICON_CODE)) {
            return R.drawable.home_icon_fast_transfer;
        } else if (iconName.equals(CREDIT_CARD_ICON_CODE)) {
            return R.drawable.home_icon_credit_card;
        } else if (iconName.equals(NO_CARD_PAYMENT_ICON_CODE)) {
            return R.drawable.home_icon_no_card_payment;
        } else if (iconName.equals(QR_CODE_ICON_CODE)) {
            return R.drawable.home_icon_qr_code;
        } else {
            return getDrawableResIdByItemCode(itemCode);
        }
    }

    public static Class<?> getClazzByItemCode(String itemCode) {
        if (COLLECT_MONEY_CODE.equals(itemCode)) {
            //刷卡收款
            return MainActivity.class;
        } else if (SCAN_PAYMENT_CODE.equals(itemCode)) {
            //扫码支付
            return ScannerCodePayActivity.class;
        } else if (QR_CODE_CODE.equals(itemCode)) {
            //扫码支付
            return ScannerCodePayActivity.class;
        } else if (MONG_HOO_CODE.equals(itemCode)) {
            //代换信用卡
            return ShowLoanHtmlActivity.class;
        } else if (HONG_SHOP_CODE.equals(itemCode)) {
            //在线商城
            return ShowMarketHtmlActivity.class;
        } else if (LOAN_PACKAGE_ICON_CODE.equals(itemCode)) {
            return null;
        } else if (STOCK_FUND_CODE.equals(itemCode)) {
            //证券开户
            return ShowHtmlActivity.class;
        } else if (QQ_IM_CODE.equals(itemCode)) {
            return AllFunctionActivity.class;
        } else if (GATHER_APP_CODE.equals(itemCode)) {
            return AllFunctionActivity.class;
        } else if (JIEAN_CODE.equals(itemCode)) {
            return JieAnHtmlActivity.class;
        } else if (MOBILE_RECHARGE_CODE.equals(itemCode)) {
            return ShowHtmlActivity.class;
        } else if (NO_CARD_PAYMENT_CODE.equals(itemCode)) {
            return ShowHtmlActivity.class;
        } else if (LOAN_CODE.equals(itemCode)) {
            return ShowHtmlActivity.class;
        } else if (FAST_TRANSFER_CODE.equals(itemCode)) {
            return SuperTransferAccountsActivity.class;
        } else if (CREDIT_CARD_CODE.equals(itemCode)) {
            return SuperTransferAccountsActivity.class;
        }
        return AllFunctionActivity.class;
    }

    public static boolean isExistComponent(String itemCode) {
        if (itemCode.equals(COLLECT_MONEY_CODE)) {
            //刷卡收款
            return true;
        } else if (itemCode.equals(SCAN_PAYMENT_CODE)) {
            //扫码支付
            return true;
        } else if (itemCode.equals(QR_CODE_CODE)) {
            //码上付
            return true;
        } else if (itemCode.equals(MONG_HOO_CODE)) {
            //代换信用卡
            return true;
        } else if (itemCode.equals(HONG_SHOP_CODE)) {
            //在线商城
            return true;
        } else if (itemCode.equals(LOAN_PACKAGE_ICON_CODE)) {
            return true;
        } else if (itemCode.equals(STOCK_FUND_CODE)) {
            //证券开户
            return true;
        } else if (itemCode.equals(QQ_IM_CODE)) {
            return true;
        } else if (itemCode.equals(GATHER_APP_CODE)) {
            return true;
        } else if (itemCode.equals(JIEAN_CODE)) {
            return true;
        } else if (itemCode.equals(MOBILE_RECHARGE_CODE)) {
            return true;
        } else if (itemCode.equals(NO_CARD_PAYMENT_CODE)) {
            return true;
        } else if (itemCode.equals(LOAN_CODE)) {
            return true;
        } else if (itemCode.equals(LOAN_PACKAGE_CODE)) {
            return true;
        } else if (itemCode.equals(FAST_TRANSFER_CODE)) {
            return true;
        } else if (itemCode.equals(CREDIT_CARD_CODE)) {
            return true;
        } else if (itemCode.equals(MY_BASIC_INFO_CODE)) {
            return true;
        } else if (itemCode.equals(MY_QUALIFICATION_INFO_CODE)) {
            return true;
        } else if (itemCode.equals(MY_COLLECT_CARD_MANAGEMENT_CODE)) {
            return true;
        } else if (itemCode.equals(MY_COLLECT_LIMIT_CODE)) {
            return true;
        } else if (itemCode.equals(MY_COLLECT_FLOW_CODE)) {
            return true;
        } else if (itemCode.equals(MY_SWIPE_SELECT_CODE)) {
            return true;
        } else if (itemCode.equals(MY_USER_NOTICE_CODE)) {
            return true;
        } else if (itemCode.equals(MY_T0_QUALIFICATION_CODE)) {
            return true;
        } else if (itemCode.equals(MY_ID_Cardate_CODE)) {
            return true;
        } else if (itemCode.equals(MY_COLLECT_WITHDRAW_CODE)) {
            return true;
        }

        return false;
    }


    @Override
    public String toString() {
        return "FunctionInfo{" +
                "itemId='" + itemId + '\'' +
                ", title='" + title + '\'' +
                ", iconResId=" + Arrays.toString(iconResId) +
                ", iconUrl='" + iconUrl + '\'' +
                ", cls=" + cls +
                ", index=" + index +
                ", showModule=" + showModule +
                ", type='" + type + '\'' +
                '}';
    }

    public static HashMap<String, FunctionInfo> getFunctionInfos(Context context) {
        DataBaseComponentModel dbModel = new DataBaseComponentModel(context);
        List<ComponentItemBean> list = dbModel.queryComponentList();
        HashMap<String, FunctionInfo> map = new HashMap<String, FunctionInfo>();
        if (list != null) {
            for (ComponentItemBean component : list) {
                HPLog.i(HPLog.YL_TAG, "component getFunctionInfos:" + component.toString());
                if (component.getItemCode() == null) {
                    continue;
                }
                String functionID = component.getItemCode();
                String functionTitle = component.getItemTitle();
                String functionIconName = component.getIconName();
                String functionType = component.getItemType();
                int functionIconResId = getDrawableResIdByFunctionIconName(functionIconName, functionID);
                Class<?> functionClazz = getClazzByItemCode(functionID);
                map.put(functionID, new FunctionInfo(functionID, functionTitle, new int[]{functionIconResId}, functionClazz, functionType));
            }
        }
        map.put(MY_BASIC_INFO_CODE, new FunctionInfo(MY_BASIC_INFO_CODE, "基本信息", new int[]{R.drawable.icon_my_info}, BaseInfoActivity.class));
        map.put(MY_QUALIFICATION_INFO_CODE, new FunctionInfo(MY_QUALIFICATION_INFO_CODE, "资质信息", new int[]{R.drawable.icon_my_qual}, QualificationInfoActivity.class));
        map.put(MY_COLLECT_CARD_MANAGEMENT_CODE, new FunctionInfo(MY_COLLECT_CARD_MANAGEMENT_CODE, "收款卡管理", new int[]{R.drawable.icon_my_cards}, BankCardManagerActivity.class));
        map.put(MY_COLLECT_LIMIT_CODE, new FunctionInfo(MY_COLLECT_LIMIT_CODE, "收款限额", new int[]{R.drawable.icon_my_quota}, TransferCashLimitManagementActivity.class));
        map.put(MY_COLLECT_FLOW_CODE, new FunctionInfo(MY_COLLECT_FLOW_CODE, "收款流水", new int[]{R.drawable.icon_my_turnover}, QueryBillsActivity.class));
        map.put(MY_SWIPE_SELECT_CODE, new FunctionInfo(MY_SWIPE_SELECT_CODE, "刷卡器连接", new int[]{R.drawable.icon_my_device}, ConnectSwiperActivity.class));
        map.put(MY_USER_NOTICE_CODE, new FunctionInfo(MY_USER_NOTICE_CODE, "用户通知", new int[]{R.drawable.icon_my_notices}, NoticeActivity.class));
        map.put(MY_T0_QUALIFICATION_CODE, new FunctionInfo(MY_T0_QUALIFICATION_CODE, "提现资质", new int[]{R.drawable.icon_my_t0}, T0QualificationActivity.class));
        map.put(MY_ID_Cardate_CODE, new FunctionInfo(MY_ID_Cardate_CODE, "证件补传", new int[]{R.drawable.icon_idcard_repairupload}, IDCardateActivity.class));
        map.put(MY_COLLECT_WITHDRAW_CODE, new FunctionInfo(MY_COLLECT_WITHDRAW_CODE, "收款提现", new int[]{R.drawable.icon_my_cash}, WithdrawActivity.class));
        return map;
    }

}
